package com.jh3502.vivo.function.tododetail.travel;

/**
 * @author harisucici
 * @date 2017/6/19
 */

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jh3502.vivo.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TodoDetailChangeCrsAdapter extends RecyclerView.Adapter<TodoDetailChangeCrsAdapter.ViewHolder> {


    private Context mContext;
    private List<TodoDetailChangeBean.CrsBean> listItems;
    private View convertView;

    public TodoDetailChangeCrsAdapter(Context context, List<TodoDetailChangeBean.CrsBean> datas) {
        this.listItems = datas;
        this.mContext = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        convertView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_todo_detail_travel_change_crs, viewGroup, false);
        ViewHolder vh = new ViewHolder(convertView);
        return vh;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, final int position) {
        viewHolder.itemView.setTag(position);
        if (listItems.get(position).getOlddata() == null || listItems.get(position).getNewdata() == null) {
            viewHolder.title.setText(listItems.get(position).getTitle() + "变更");
            return;
        }

        SpannableString spTitle = new SpannableString(listItems.get(position).getTitle() + "：由");
        ForegroundColorSpan fsTitle = new ForegroundColorSpan(Color.parseColor("#FF666666"));
        spTitle.setSpan(fsTitle, 0, spTitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        viewHolder.title.append(spTitle);

        SpannableString spOld = new SpannableString(listItems.get(position).getOlddata());
        ForegroundColorSpan fsOld = new ForegroundColorSpan(Color.parseColor("#FFF36C60"));
        spOld.setSpan(fsOld, 0, spOld.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        viewHolder.title.append(spOld);

        SpannableString spMid = new SpannableString("变更为");
        ForegroundColorSpan fsMid = new ForegroundColorSpan(Color.parseColor("#FF666666"));
        spMid.setSpan(fsMid, 0, spMid.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        viewHolder.title.append(spMid);

        SpannableString spNew = new SpannableString(listItems.get(position).getNewdata());
        ForegroundColorSpan fsNew = new ForegroundColorSpan(Color.parseColor("#FFF36C60"));
        spNew.setSpan(fsNew, 0, spOld.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        viewHolder.title.append(spNew);

    }


    @Override
    public int getItemCount() {
        return listItems.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.title)
        TextView title;

        public ViewHolder(@NonNull View view) {

            super(view);
            ButterKnife.bind(this, view);
        }
    }


}